//
//  Card.m
//  Memory5
//
//  Created by Jin Hu on 2009/12/10.
//  Copyright 2009 Philips Research. All rights reserved.
//

#import "Card.h"


@implementation Card


- (id)initWithFrame:(CGRect)frame front:(NSString*)f{
	if (self = [super initWithFrame:frame]) {
        back= [UIImage imageNamed:@"back.png"];
		front = [UIImage imageNamed:f];
		face=f;
		[face retain];
		[back retain];
		[front retain];
		image = back;
//		[self addTarget: self action: @selector(flipToFront:) forControlEvents: UIControlEventTouchUpInside];

	}
    return self;	
}
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
	//[super drawRect:rect];
	CGContextRef context=UIGraphicsGetCurrentContext();
	CGContextSetRGBFillColor(context, 1, 1, 1, 0.5); //shadow
	CGContextFillRect(context, rect);

	[image drawInRect:rect];
//	
//	CGContextSetRGBFillColor(context, 1, 0, 0, 1); //shadow
//	CGContextFillRect(context, rect);
	//CGContextStrokeRect(context,eLine);
}


- (void)dealloc {
    [super dealloc];
}

-(IBAction)flipToFront:(id)sender{
	[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft  forView:self cache:YES];
	[UIView commitAnimations];
	image=front;
	[self setNeedsLayout];
	[self setNeedsDisplay];
}
-(IBAction)flipToBack:(id)sender{
	[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight  forView:self cache:YES];
	[UIView commitAnimations];
	image=back;
	[self setNeedsLayout];
	[self setNeedsDisplay];
}
-(NSString*)getFace{
	return face;
}
@end

